package vip.xumy.admin.sys.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import vip.xumy.admin.sys.pojo.UserItem;
import vip.xumy.admin.sys.service.UserItemService;
import vip.xumy.admin.utils.LoginUtil;
import vip.xumy.core.pojo.com.AjaxResponse;
import vip.xumy.core.utils.StringUtil;

/**
 * @author:mengyxu
 * @date:2020年3月18日
 */

@RestController
@RequestMapping("public/item")
public class UserItemController {
	@Autowired
	private UserItemService itemService;

	@RequestMapping(value = "list", method = RequestMethod.GET)
	public List<UserItem> queryList(UserItem example, HttpServletRequest request) {
		String userId = LoginUtil.getUserId(request);
		if (StringUtil.isEmpty(userId)) {
			return null;
		}
		example.setUserId(userId);
		Integer page = example.getPage();
		Integer size = example.getSize();
		if (page != null && size != null) {
			example.setLimitStart((page - 1) * size);
		}
		return itemService.queryByExample(example);
	}

	@RequestMapping(value = "read", method = RequestMethod.POST)
	public AjaxResponse queryList(Integer id, HttpServletRequest request) {
		itemService.read(id);
		return new AjaxResponse(true, null);
	}

}
